package cn.lystudio.rohmtimeopwide_background_v11.mapper;

import cn.lystudio.rohmtimeopwide_background_v11.entity.po.ShiftCapacityRecordPO;
import cn.lystudio.rohmtimeopwide_background_v11.entity.vo.ShiftCapacityRecordVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShiftCapacityRecordMapper extends BaseMapper<ShiftCapacityRecordPO> {
    @Select("SELECT record.*,users.userFullName \t\n" +
            "FROM t_shift_capacity_record record \t\n" +
            "LEFT JOIN t_users users ON users.userCode=record.userCode  " +
            "WHERE 1=1 \t\n" +
            "AND  record.machineNo=#{machineNo} \t\n" +
            "AND record.recordTimeDT > #{beginDate} \t\n" +
            "AND record.recordTimeDT <= #{endDate} \t\n " +
            "ORDER BY record.recordTimeDT DESC")
    List<ShiftCapacityRecordVO> getShiftCapaRecordTimeLine(@Param("machineNo")String machineNo, @Param("beginDate")String beginDate, @Param("endDate")String endDate);

    @Select("<script>" +
        "SELECT\n" +
        "\tmachineNo,\n" +
        "\tDATE_FORMAT(recordTimeDT, '%Y-%m-%d') as recordTimeDT,\n" +
        "\tSUM(planOutput) as planOutput,\n" +
        "\tSUM(actualCommonOutput) as actualCommonOutput,\n" +
        "\tSUM(actualHROutput) as actualHROutput,\n" +
        "\tSUM(bj2Output) as bj2Output,\n" +
        "\tSUM(dsOutput) as dsOutput,\n" +
        "\tSUM(defect) as defect\n" +
        "FROM t_shift_capacity_record \n" +
        "WHERE 1=1 AND   " +
        "<foreach item='item' collection='machineNoList' open=' machineNo IN (' separator=',' close=')'>"+
            "#{item}" +
        "</foreach>" +
        "AND recordTimeDT LIKE CONCAT('%',#{selectDate},'%')\n" +
        "GROUP BY machineNo,DATE_FORMAT(recordTimeDT, '%Y-%m-%d')  " +
        "ORDER BY machineNo" +
        "</script>")
    List<ShiftCapacityRecordPO> getCapa4Home(@Param("machineNoList")List<String> machineNolist,
                                             @Param("selectDate")String selectDate);
}
